USE [OctoNetApps]
GO

/****** Object:  StoredProcedure [classified].[ClassifiedResources_Get]    Script Date: 05/25/2011 07:02:14 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO




CREATE PROCEDURE [classified].[ClassifiedResources_Get]
	@ResourceID bigint,
	@NeedCurrency bit
AS
BEGIN

	SET NOCOUNT ON;
	
	IF (@NeedCurrency = 1)
	BEGIN
		SELECT CurrencyID, Code, Description FROM classified.ClassifiedCurrency
	END
		
    SELECT 
		CAST (defaultLocation.Lat as float) as latitude,
		CAST (defaultLocation.Long as float) as longitude,
		AllowAnonymousAds,
		Comments,
		AllowRenewal, 
		AutoExpireAnonymousDays,
		AutoExpireNonAnonymousDays,
		AdApprove,
		CurrencyID,
		AdminMail,
		CAST (0 as bit) as IsMaster
     FROM classified.ClassifiedResources
	WHERE ResourceID = @ResourceID AND MasterResourceID IS NULL
	
	IF @@ROWCOUNT = 0
	BEGIN
		SELECT 
		CAST (defaultLocation.Lat as float) as latitude,
		CAST (defaultLocation.Long as float) as longitude,
		AllowAnonymousAds,
		Comments,
		AllowRenewal, 
		AutoExpireAnonymousDays,
		AutoExpireNonAnonymousDays,
		AdApprove,
		CurrencyID,
		AdminMail,
		CAST (1 as bit) as IsMaster
		 FROM classified.ClassifiedResources
		WHERE ResourceID IN (SELECT MasterResourceID FROM classified.ClassifiedResources WHERE ResourceID = @ResourceID)
	
		SELECT CAST (defaultLocation.Lat as float) as latitude, CAST (defaultLocation.Long as float) as longitude,AdminMail 
		FROM classified.ClassifiedResources WHERE ResourceID = @ResourceID
	
	END
END


GO


